<template>
  <el-card>
    <div class="cable">
      <div class="search">
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item label="物料名称">
            <el-input
              v-model="formInline.materialName"
              placeholder="请输入物料名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="物料编号">
            <el-input
              v-model="formInline.materialNumber"
              placeholder="请输入物料编号"
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-button class="detail" @click="onSubmit">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table
        :data="Data"
        border
        style="width: 100%"
        stripe
        :row-style="{ height: '60px', padding: '0 0' }"
      >
        <el-table-column prop="materialName" label="物料名称" width="180">
        </el-table-column>
        <el-table-column prop="materialNumber" label="物料编号" width="180">
        </el-table-column>
        <el-table-column prop="guige" label="规格型号"> </el-table-column>
        <el-table-column prop="unit" label="单位"> </el-table-column>
        <el-table-column prop="initNum" label="入库数量"> </el-table-column>
        <el-table-column prop="rushNum" label="出库数量"> </el-table-column>
      </el-table>
      <div class="block" style="float: right">
        <el-pagination
          layout="prev, pager, next"
          :total="pageNum"
          :page-size="pageSize"
          @current-change="pageChange"
        >
        </el-pagination>
      </div>
    </div>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      formInline: {
        materialName: '',
        materialNumber: ''
      },
      pageNum: 10,
      pageSize: 10,
      page: 1
    };
  },
  methods: {
    onSubmit() {
      this.axios({
        url: 'http://localhost:8080/nan/getAllMaterial',
        params: this.formInline
      }).then(res => {
        if (res.data.code === 200) {
          this.tableData = res.data.data.list;
        }
      });
    },
    pageChange(e) {
      this.page = e;
    }
  },
  mounted() {
    this.axios({
      url: 'http://localhost:8080/nan/getAllMaterial'
    }).then(res => {
      if (res.data.code === 200) {
        this.tableData = res.data.data.list;
        this.pageNum = this.tableData.length;
      }
    });
  },
  computed: {
    Data() {
      // 0-4   page   pagenum   pagesize
      // 5-9
      return this.tableData.slice(
        (this.page - 1) * this.pageSize,
        this.page * this.pageSize
      );
    }
  }
};
</script>

<style></style>
